<template>
  <el-dialog title="装箱清单选择"
             v-if="showFlag"
             :visible.sync="showFlag"
             :modal=false
             width="80%"
             center
  >
    <el-table v-loading="loading" :data="orderLineList" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column width="55" align="center">
        <template v-slot="scope">
          <el-radio v-model="selectedId" :label="scope.row.materialStockId" @change="handleRowChange(scope.row)">
            {{ "" }}
          </el-radio>
        </template>
      </el-table-column>
      <el-table-column label="产品物料编码" width="120px" align="center" prop="itemCode"/>
      <el-table-column label="产品物料名称" width="150px" align="center" prop="itemName" :show-overflow-tooltip="true"/>
      <el-table-column label="规格型号" align="center" prop="specification" :show-overflow-tooltip="true"/>
      <el-table-column label="单位" align="center" prop="unitOfMeasure"/>
      <el-table-column label="批次号" width="100px" align="center" prop="batchCode" :show-overflow-tooltip="true"/>
      <el-table-column label="仓库" align="center" prop="warehouseName"/>
      <el-table-column label="库区" align="center" prop="locationName"/>
      <el-table-column label="库位" align="center" prop="areaName"/>
      <el-table-column label="出库数量" align="center" prop="quantitySalse">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.quantitySalse">{{ scope.row.quantitySalse }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="出库检验单号" width="150px" align="center" prop="oqcCode"/>
    </el-table>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag=false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {getSoCodeInfo} from "@/api/mes/wm/package";
export default {
  name: "PackageXsOrderSelect",
  data() {
    return {
      showFlag: false,
      // 遮罩层
      loading: true,
      // 选中数组
      selectedId: null,
      selectedRow: null,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 库存记录表格数据
      orderLineList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单参数
      form: {},
    };
  },
  props: {
    propSoCode: null,
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询库存记录列表 */
    getList() {
      this.loading = true;
      getSoCodeInfo(this.propSoCode).then(res =>{
        this.orderLineList = res.data
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    //行双击选中
    handleRowDbClick(row) {
      if (row) {
        this.selectedRow = row;
        this.$emit('onSelected', this.selectedRow);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    //确定选中
    confirmSelect() {
      if (this.selectedId == null || this.selectedId == 0) {
        this.$notify({
          title: '提示',
          type: 'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected', this.selectedRow);
      this.showFlag = false;
    }
  }
};
</script>
